<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>{{ menuTitle.main }}</el-breadcrumb-item>
      <el-breadcrumb-item>{{ menuTitle.item }}</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图 -->
    <el-card class="box-card">
      <el-table :data="rightsList" border>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="rightName" label="权限名称"></el-table-column>
        <el-table-column prop="keyword" label="权限关键字"></el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 面包屑导航标题
      menuTitle: {
        main: '',
        item: ''
      },
      // 权限列表
      rightsList: []
    }
  },
  created() {
    this.getMenuList()
    this.getRightList()
  },
  methods: {
    // 获取面包屑导航标题
    async getMenuList() {
      const { data: res } = await this.$axios.get('/menu/getMenuList.do')
      if (!res.flag) return this.$message.error(res.message)
      // 获取当前激活路径
      const activePath = window.sessionStorage.getItem('activePath')
      // 循环判断激活路径对应的路径名称
      res.data.forEach(value => {
        value.menuItem.forEach(item => {
          if (item.path === activePath) {
            this.menuTitle.item = item.title
            this.menuTitle.main = value.title
          }
        })
      })
    },
    // 获取权限列表
    async getRightList() {
      const { data: res } = await this.$axios.get('/right/findAll.do')
      if (!res.flag) return this.$message.error(res.message)
      this.rightsList = res.data
    }
  }
}
</script>

<style lang="less" scoped>
@import '../../assets/css/table.css';
</style>
